<?php
require_once("conn.php");
require_once("functions.php");
//$today = date("Y-m-d h:m:s", time());
////转换成Unix时间戳
//echo strtotime($today) . "<br>";
//echo $today;
?>
<html>
<head>
    <meta charset="UTF-8">
    <title>微有趣</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="./assets/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="./assets/css/rank.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        function changeSize() {
            var propo = $(window).width() / 640;
            $('html').css('font-size', 40 * propo + 'px');
        }
        ;
        changeSize();
        $(window).resize(function () {
            changeSize();
        });
    </script>
</head>
<body>
<div class="wrap">
    <div class="rank">
        <div class="nav">
            <div class="left clearfix">
                七日排行
            </div>
            <div class="right clearfix">
                总排行
            </div>
        </div>
        <div class="con">
            <ul class="title clearfix">
                <li class="nav_one">排名</li>
                <li class="nav_two">用户头像</li>
                <li class="nav_three">用户ID</li>
                <li class="nav_four">好友数</li>
                <li class="nav_five">个人积分</li>
            </ul>
            <!--					七日排行-->
            <ul id="list1" class="data clearfix">
                <?php
                $delWeek = 60 * 60 * 24 * 7;
                $day = date("Y-m-d h:m:s", time() - $delWeek);
                $sevenSql = "select sum(score) as allScore,uid from score_detail WHERE day > '{$day}' GROUP BY uid ORDER BY SUM(score) desc limit 50";
                $sevenRow = $mysql->query($sevenSql);
                //            echo "<pre>";
                //            print_r($sevenRow);
                $i = 0; //排名
                foreach ($sevenRow as $value) {
                    $i++;
                    $userInfo = $mysql->query("select * from `user` WHERE id = {$value['uid']}");
                    $studentNum = $mysql->query("select count(*) as num from `user` WHERE `pid` = {$value['uid']} AND `login` = 1");
//                    echo "<pre>";
//                    print_r($userInfo);exit;
                    ?>
                    <li>
                        <span class="one"><?= $i ?></span>
                        <span class="two"><img src="<?php
                        if ($userInfo[0]['head'] != null) {
                            echo $userInfo[0]['head'];
                        } else {
                            echo "./assets/images/rank/head.png";
                        }
                        ?>"/></span>
                        <span class="three"><?= substr($userInfo[0]['id'],0,3)."**" ?></span>
                        <span class="four"><?= $studentNum[0]['num'] ?></span>
                        <span class="five"><?= $value['allScore'] ?></span>
                    </li>
                <?php } ?>
            </ul>


            <!--					总排行-->
            <ul style="display: none" id="list2" class="data clearfix">
                <?php
                $allSql = "select score,id from user ORDER BY score DESC limit 50";
                $allRow = $mysql->query($allSql);
                $i = 0;
                foreach ($allRow as $value) {
                    $i++;
                    $userInfo = $mysql->query("select * from `user` WHERE id = {$value['id']}");
                    $studentNum = $mysql->query("select count(*) as num from `user` WHERE `pid` = {$value['id']} AND `login` = 1");
                    ?>
                    <li>
                        <span class="one"><?= $i ?></span>
                        <span class="two"><img src="<?php
                        if ($userInfo[0]['head'] != null) {
                            echo $userInfo[0]['head'];
                        } else {
                            echo "./assets/images/rank/head.png";
                        }
                        ?>"/></span>
                        <span class="three"><?= substr($userInfo[0]['id'],0,3)."**" ?></span>
                        <span class="four"><?= $studentNum[0]['num'] ?></span>
                        <span class="five"><?= $value['score'] ?></span>
                    </li>
                <?php } ?>
            </ul>
        </div>

    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".left").css("border-bottom", "2px solid #3cb715");
        $(".left").click(function () {
            $(this).css("border-bottom", "2px solid #3cb715").siblings().css("border", "none");
            $("#list1").show();
            $("#list2").hide();

        });
        $(".right").click(function () {
            $(this).css("border-bottom", "2px solid #3cb715").siblings().css("border", "none");
            $("#list2").show();
            $("#list1").hide();
        });
    })
</script>
</body>
</html>
